package com.cci.kangdao.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.GMApplyService;
import com.cci.kangdao.utilTool.ParameterTool;

/**
 * 申请Guidanz Mobile权限
 * @author Eric Mu
 *
 */
@Controller
public class GMApplyController {

	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private GMApplyService gmApplyService;
	
	/**
	 * 验证用户是否可申请Guidanz Mobile权限
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/qualityCheck.aspx")
	public ModelAndView qualityCheck(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyService.qualityCheck(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			String msg = "{\"status\": 1,\"msg\": \"系统异常\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * 创建Guidanz Mobile申请记录
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/createGMApply.aspx", method=RequestMethod.POST)
	public ModelAndView createGMApply(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyService.createGMApply(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			String msg = "{\"status\": 1,\"msg\": \"系统异常\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * 解除Guidanz Mobile权限接口
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/deauthorization.aspx", method=RequestMethod.POST)
	public ModelAndView deauthorization(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyService.deauthorization(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			String msg = "{\"status\": 1,\"msg\": \"系统异常\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * 审核通过Guidanz Mobile权限申请
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/approveApply.aspx", method=RequestMethod.POST)
	public ModelAndView approveApply(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyService.approveApply(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			String msg = "{\"status\": 1,\"msg\": \"系统异常\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	@RequestMapping(value = "/checkGMUsableNum.aspx", method = RequestMethod.POST)
	public ModelAndView checkGMUsableNum (HttpServletRequest request,
										  HttpServletResponse response) throws Exception{
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyService.checkGMUsableNum(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": 1,\"msg\": \"系统异常\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	// 权限判断：我的消息-GM消息
	@RequestMapping(value = "/checkGMAuthForMessage.aspx", method = RequestMethod.GET)
	public ModelAndView checkGMAuthFormessage (HttpServletRequest request,
										  HttpServletResponse response) throws Exception{
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyService.checkGMAuthForMessage(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": 1,\"msg\": \"系统异常\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
}
